package com.hnl.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.dao.MiscDAO;
import com.hnl.dao.RoleDAO;
import com.hnl.dao.TalentDAO;
import com.hnl.dao.UserDAO;
import com.hnl.to.Misc;
import com.hnl.to.Role;
import com.hnl.to.Talent;
import com.hnl.to.User;

public class DAOHelperUtil {
	public static final Logger LOG = LoggerFactory
			.getLogger(DAOHelperUtil.class);

	public static String getReferralTextByID(Integer referralID) {
		String referralText = null;
		try {
			TalentDAO referralDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getTalentDAO();
			// Referral referral=referralDAO.lo
			Talent referral = referralDAO.loadTalent(referralID);
			if (referral.geteFirstname() == "" && referral.geteLastname() == "") {
				referralText = referral.getcFirstname() + " "
						+ referral.getcLastname();
			} else {
				referralText = referral.geteFirstname() + " "
						+ referral.geteLastname();
			}
		} catch (DAOException e) {
			;
			LOG.error("Error in DAOHelperUtil referrl Info. ", e);
		}
		return referralText;
	}

	public static String getUserTextByID(Integer userID) {
		String userText = null;

		try {
			UserDAO userDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getUserDAO();

			User user = userDAO.loadUserByUserID(userID);
			userText = user.getFirstname() + " " + user.getLastname();
		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		}

		return userText;
	}

	public static String getMiscTextByID(Integer miscID) {
		String miscText = null;

		try {
			MiscDAO miscDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getMiscDAO();

			Misc misc = miscDAO.loadMisc(miscID);
			miscText = misc.getMiscName();
		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		}

		return miscText;
	}

	public static Integer getRoleNameIDByRoleID(Integer roleID) {
		Integer roleNameID = null;
		try {
			RoleDAO roleDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getRoleDAO();
			Role role = roleDAO.loadRoleByRoleID(roleID);
			roleNameID = role.getRoleName();
		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		}

		return roleNameID;
	}

}
